{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Configure through code.\n",
    "Restart the kernel here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO: Hello logging world\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "import sys\n",
    "root_logger = logging.getLogger()\n",
    "handler = logging.StreamHandler(sys.stdout)\n",
    "formatter = logging.Formatter(\"%(levelname)s: %(message)s\")\n",
    "handler.setFormatter(formatter)\n",
    "root_logger.addHandler(handler)\n",
    "root_logger.setLevel(\"INFO\")\n",
    "\n",
    "logging.info(\"Hello logging world\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Configure with dictConfig.\n",
    "Restart the kernel here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO: Hello logging world\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "from logging.config import dictConfig\n",
    "\n",
    "dictConfig({\n",
    "    \"version\": 1,\n",
    "    \"formatters\": {\n",
    "        \"short\":{\n",
    "            \"format\": \"%(levelname)s: %(message)s\",\n",
    "        }\n",
    "    },\n",
    "    \"handlers\": {\n",
    "        \"console\": {\n",
    "            \"class\": \"logging.StreamHandler\",\n",
    "            \"formatter\": \"short\",\n",
    "            \"stream\": \"ext://sys.stdout\",\n",
    "            \"level\": \"DEBUG\",\n",
    "        }\n",
    "    },\n",
    "    \"loggers\": {\n",
    "        \"\": {\n",
    "            \"handlers\": [\"console\"],\n",
    "            \"level\": \"INFO\"\n",
    "        }   \n",
    "    }\n",
    "})\n",
    "logging.info(\"Hello logging world\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Configure with basicConfig.\n",
    "Restart the kernel here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO: Hello there!\n"
     ]
    }
   ],
   "source": [
    "import sys\n",
    "import logging\n",
    "logging.basicConfig(\n",
    "    level=\"INFO\",\n",
    "    format=\"%(levelname)s: %(message)s\",\n",
    "    stream=sys.stdout\n",
    ")\n",
    "logging.info(\"Hello there!\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Configure with fileconfig.\n",
    "Restart the kernel here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "INFO: Hello there!\n"
     ]
    }
   ],
   "source": [
    "import logging\n",
    "from logging.config import fileConfig\n",
    "fileConfig(\"logging-config.ini\")\n",
    "logging.info(\"Hello there!\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
